<template>
  <div>
    <el-dialog title="深化图纸确认"
               :visible.sync="dialogVisible"
               width="50%"
               :before-close="handleClose">
      <el-row :gutter="20">
        <el-form ref="requestParam"
                 :model="requestParam"
                 :rules="rules"
                 label-width="80px">
          <el-col :span="24">
            <el-form-item label="是否确认"
                          prop="confirm_status">
              <el-radio-group v-model="requestParam.confirm_status"
                              @change="onIsConfChange">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <!-- prop="reply_comments" -->
            <el-form-item label="回复意见">
              <el-input type="textarea"
                        :rows="3"
                        placeholder="请输入回复意见"
                        v-model="requestParam.reply_comments">
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24"
                  class="bottom-box">
            <el-button type="primary"
                       @click="onSure('requestParam')">确定</el-button>
            <el-button @click="onCancel('back')">取消</el-button>
          </el-col>
        </el-form>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { deepDesignConfirmApi } from '@/services/ProjectCenter';
export default {
  props: {
    catchBackFunc: {
      type: Function
    },
    objRow: {
      type: Object,
      default: () => {
        return {}
      }
    },
    deepDesignConfimDialog: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  data () {
    return {
      dialogVisible: false,
      requestParam: {
        paper_id: '',
        confirm_status: '',
        reply_comments: ''
      },
      rules: {
        confirm_status: [
          { required: true, message: '是否确认不能为空', trigger: ['blur', 'change'] }
        ],
        reply_comments: [
          { required: true, message: '回复意见不能为空', trigger: ['blur', 'change'] }
        ]
      }
    }
  },
  methods: {
    onIsConfChange (val) {//是否确认值改变时触发的事件
      console.log('是否确认val=', val)
    },
    handleClose (done) {
      this.onCancel('back');
      this.dialogVisible = false;
      done()
    },
    onCancel (typeV) {//取消
      this.$refs.requestParam.resetFields();
      this.$emit('update:objRow', {});
      this.$emit('update:deepDesignConfimDialog', false);
      if (typeV == 'save') {
        this.catchBackFunc('save');
      } else {
        this.catchBackFunc('back');
      }
    },
    deepDesignConfirm () {//深化设计确认
      deepDesignConfirmApi.deepConfirm({
        data: this.requestParam//深化设计确认传参
      }).then((res) => {
        if (res.code == 0) {
          this.onCancel('save');
          this.$message.success('操作成功')
        }
      }).catch((error) => {
        console.log(error)
      })
    },
    onSure (data) {//确定
      this.$refs[data].validate((valid) => {
        if (valid) {
          this.deepDesignConfirm();//深化设计确认
        } else {
          return false;
        }
      })
    },
    getInfo () {//回显
      let confirmStatus = Number(this.objRow.status);//是否确认的状态
      let obj = Object.assign({}, this.objRow);//拷贝
      this.$set(obj, 'confirm_status', confirmStatus)
      this.requestParam = obj;
    }
  },
  watch: {
    deepDesignConfimDialog (n, o) {
      this.getInfo();//数据回显
      this.dialogVisible = n;
    }
  },
  created () {
    this.getInfo();//回显
    this.dialogVisible = this.deepDesignConfimDialog;
  }
}
</script>

<style scoped lang="scss">
.bottom-box {
  text-align: right;
}
</style>